# -*- coding: utf-8 -*-
import commonlib
import traceback, os, datetime
from MongoModel import MongoModel
from MongoDbLog import MongoDbLog


url = " http://m11.nhaccuatui.com/RestfulAPI.ashx"



post = {'secretkey': 'nct@mobile!team', 'action': 'topNewSong', 'numbersongs': '100'}

tree = commonlib.getXMLTree(url, post, isXML=True, useragent="NCTMusic/1.0 CFNetwork/485.12.7")

for item in tree.xpath("//SongTitle"):
    print commonlib.getElementText(item)


class NCT():
    
    def __init__(self):
        self.userAgent = 'NCTMusic/1.0 CFNetwork/485.12.7 Darwin/10.4.0'
        self.url = 'http://m11.nhaccuatui.com/RestfulAPI.ashx'
        self.post = {'secretkey': 'nct@mobile!team'}
    
    def getListCategories(self):
        post = self.post
        post['action'] = 'genres'
        tree = commonlib.getXMLTree(url, post, isXML=True, useragent=self.userAgent, outputHTML=True)
    
if __name__ == '__main__':
    
    nct = NCT()
    nct.getListCategories()
    
    os._exit(1)
    
'''
---- lay danh muc


POST http://m11.nhaccuatui.com/RestfulAPI.ashx HTTP/1.1
Host: m11.nhaccuatui.com
User-Agent: NCTMusic/1.0 CFNetwork/485.12.7 Darwin/10.4.0
Content-Length: 39
Content-Type: application/x-www-form-urlencoded
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive
Connection: keep-alive

secretkey=nct@mobile!team&action=genres


---- list song by danh muc



secretkey=nct@mobile!team&action=getListSongByGenre&genreid=5015&currentpage=1&perpage=10


---- top new song



secretkey=nct@mobile!team&action=topNewSong&numbersongs=20


---- top hot song


secretkey=nct@mobile!team&action=topHotSong&numbersongs=20

---- playlist chonloc



secretkey=nct@mobile!team&action=searchPlaylist&keyword=&currentpage=1&perpage=10&searchtype=chonloc


---- search bai hat


secretkey=nct@mobile!team&action=search&keyword=anh&currentpage=1&perpage=30&searchtype=chonloc

---- search playlist

secretkey=nct@mobile!team&action=searchPlaylist&keyword=anh&currentpage=1&perpage=30&searchtype=chonloc
'''

